package demoMod.stsconsole.events;

import java.util.ArrayList;
import java.util.List;

public abstract class EventNode {
    public List<EventNode> next = new ArrayList<>();
    public List<EventOption> options = new ArrayList<>();
    public String bodyText;
    public boolean isActive = true;
    protected int selectedIndex = 0;
    private final AbstractEvent event;

    public EventNode(AbstractEvent event) {
        this.event = event;
    }

    public String getUpdatedDescription() {
        return isActive ? bodyText : next.get(selectedIndex).getUpdatedDescription();
    }

    public List<String> getChoices() {
        if (!isActive) return next.get(selectedIndex).getChoices();
        List<String> ret = new ArrayList<>();
        for (EventOption option : options) {
            ret.add(option.getUpdatedDescription());
        }
        return ret;
    }

    public abstract void onChooseOption(int optionIndex);

    public AbstractEvent getEvent() {
        return event;
    }

    public EventNode getNode() {
        return isActive ? this : next.get(selectedIndex).getNode();
    }

    public int getSelectedIndex() {
        return selectedIndex;
    }

    public void setSelectedIndex(int selectedIndex) {
        this.selectedIndex = selectedIndex;
    }

    public int getOptionSize() {
        return isActive ? options.size() : next.get(selectedIndex).getOptionSize();
    }
}
